package org.zebra.web.annotation.sensitive;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.DesensitizedUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.function.Function;

/**
 * 脱敏策略
 *
 * @author zhanghongbin
 */
@AllArgsConstructor
@Getter
public enum SensitiveStrategy {

    /**
     * 身份证脱敏
     */
    ID_CARD(s -> DesensitizedUtil.idCardNum(s, 3, 4)),

    /**
     * 手机号脱敏
     */
    PHONE(DesensitizedUtil::mobilePhone),

    /**
     * 地址脱敏
     */
    ADDRESS(s -> DesensitizedUtil.address(s, 8)),

    /**
     * 邮箱脱敏
     */
    EMAIL(DesensitizedUtil::email),

    /**
     * 银行卡
     */
    BANK_CARD(DesensitizedUtil::bankCard),

    /**
     * 用户姓名
     */
    USER_NAME(SensitiveStrategy::userName);

    private final Function<String, String> desensitizer;

    private static String userName(String userName) {
        // return StringUtils.rightPad(StringUtils.left(userName, 1), userName.length(),"*");
        return CharSequenceUtil.hide(userName, 1, userName.length());
    }
}
